1 /** 2 3 Copyright by The HDF Group. 4 Copyright by the Board of Trustees of the University of Illinois. 5 All rights reserved. 6 7 This file is part of HDF5. The full HDF5 copyright notice, including 8 terms governing use, modification, and redistribution, is contained in 9 the files COPYING and Copyright.html. COPYING can be found at the root 10 of the source code distribution tree; Copyright.html can be found at the 11 root level of an installed copy of the electronic HDF5 document set and 12 is linked from the top-level documents page. It can also be found at 13 http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have 14 access to either file, you may request a copy from help@hdfgroup.org. 15 16 Ported 2015 to the D Programming Language by Laeeth Isharc 17 */ 18 19 /** 20 hdf5.wraphl - D wrappers for 'high level' C API for HDF5 21 22 Not tested and may not be complete 23 */ 24 25 module hdf5.wraphl; 26 import hdf5.bindings.hlapi; 27 import hdf5.bindings.api; 28 import hdf5.bindings.enums; 29 import core.memory:GC; 30 import std.conv:to; 31 /** 32 Helper Functions 33 */ 34 35 char** toCPointerArray(string[] inp) 36 { 37 auto ret=cast(char**) GC.calloc((char *).sizeof); 38 foreach(i, item;inp) 39 *(ret+i)=cast(char*)(to!string(item)~"\0").ptr; 40 return ret; 41 } 42 43 /** 44 So far no real wrapping done here 45 Just copy and paste from main bindings so we have templates 46 for nicer D wrapping 47 */ 48 49 /+ 50 51 struct H5DO 52 { 53 void write_chunk(hidh_t dset_id, hid_t dxpl_id, uint filters, const hsize_t *offset, size_t data_size, const (void*) buf) 54 { 55 enforce(H5DOwrite_chunk(dset_id,dxpl_id,filters,offset,data_size,buf) 56 } 57 } 58 /** 59 H5DSpublic 60 */ 61 enum DimensionScaleClass = "DIMENSION_SCALE"; 62 enum DimensionList = "DIMENSION_LIST"; 63 enum ReferenceList = "REFERENCE_LIST"; 64 enum DimensionLabels = "DIMENSION_LABELS"; 65 66 alias DIMENSION_SCALE_CLASS = DimensionScaleClass; 67 alias DIMENSION_LIST = DimensionList; 68 alias REFERENCE_LIST = ReferenceList; 69 alias DIMENSION_LABELS = DimensionLabels; 70 71 72 alias H5DS_iterate_t = herr_t function(hid_t dset, unsigned dim, hid_t scale, void *visitor_data); 73 herr_t H5DSattach_scale( hid_t did, hid_t dsid, uint idx); 74 herr_t H5DSdetach_scale( hid_t did, hid_t dsid, uint idx); 75 herr_t H5DSset_scale( hid_t dsid, const (char*) dimname); 76 int H5DSget_num_scales( hid_t did, uint dim); 77 herr_t H5DSset_label( hid_t did, uint idx, const (char*) label); 78 ssize_t H5DSget_label( hid_t did, uint idx, char *label, size_t size); 79 ssize_t H5DSget_scale_name( hid_t did, char *name, size_t size); 80 htri_t H5DSis_scale( hid_t did); 81 herr_t H5DSiterate_scales( hid_t did, uint dim, int *idx, H5DS_iterate_t visitor, void *visitor_data); 82 htri_t H5DSis_attached( hid_t did, hid_t dsid, uint idx); 83 84 /** 85 H5IMpublic 86 */ 87 struct H5Image 88 { 89 90 //void makeImage8Bit( 91 herr_t H5IMmake_image_8bit( hid_t loc_id, const (char*) dset_name, hsize_t width, hsize_t height, const (ubyte*) buffer ); 92 herr_t H5IMmake_image_24bit( hid_t loc_id, const (char*) dset_name, hsize_t width, hsize_t height, const (char*) interlace, 93 const (ubyte*) buffer ); 94 herr_t H5IMget_image_info( hid_t loc_id, const (char*) dset_name, hsize_t *width, hsize_t *height, hsize_t *planes, char *interlace, 95 hssize_t *npals ); 96 herr_t H5IMread_image( hid_t loc_id, const (char*) dset_name, ubyte *buffer ); 97 herr_t H5IMmake_palette( hid_t loc_id, const (char*) pal_name, const hsize_t *pal_dims, const (ubyte*) pal_data ); 98 herr_t H5IMlink_palette( hid_t loc_id, const (char*) image_name, const (char*) pal_name ); 99 herr_t H5IMunlink_palette( hid_t loc_id, const (char*) image_name, const (char*) pal_name ); 100 herr_t H5IMget_npalettes( hid_t loc_id, const (char*) image_name, hssize_t *npals ); 101 herr_t H5IMget_palette_info( hid_t loc_id, const (char*) image_name, int pal_number, hsize_t *pal_dims ); 102 herr_t H5IMget_palette( hid_t loc_id, const (char*) image_name, int pal_number, ubyte *pal_data ); 103 herr_t H5IMis_image( hid_t loc_id, const (char*) dset_name ); 104 herr_t H5IMis_palette( hid_t loc_id, const (char*) dset_name ); 105 106 /** 107 H5LPTpublic 108 */ 109 110 // Flag definitions for H5LTopen_file_image() 111 enum H5LT_FILE_IMAGE_OPEN_RW = 0x0001 // Open image for read-write 112 enum H5LT_FILE_IMAGE_DONT_COPY = 0x0002; // The HDF5 lib won't copy user supplied image buffer. The same image is open with the 113 // core driver. 114 enum H5LT_FILE_IMAGE_DONT_RELEASE= 0x0004; // The HDF5 lib won't deallocate user supplied image buffer. The user application is responsible. 115 enum H5LT_FILE_IMAGE_ALL = 0x0007; 116 117 enum H5LT_lang_t 118 { 119 H5LT_LANG_ERR = -1, /*this is the first*/ 120 H5LT_DDL = 0, /*for DDL*/ 121 H5LT_C = 1, /*for C*/ 122 H5LT_FORTRAN = 2, /*for Fortran*/ 123 H5LT_NO_LANG = 3 /*this is the last*/ 124 } 125 126 /** 127 128 Make dataset functions 129 130 */ 131 132 struct H5Lite 133 { 134 void make(T)(hid_t locID,string datasetName, hsize_t[] dims, hid_t typeID, in T[] data) 135 { 136 enforce(H5LTmake_dataset(locID,datasetName.toStringz,cast(int)dims.length,dims.ptr,typeID,data.ptr)>=0, 137 new Exception("H5Lite.make error")); 138 } 139 140 void make(hid_t locID,string datasetName, hsize_t[] dims, hid_t typeID, in char[] data) 141 { 142 enforce(H5LTmake_dataset_char(locID,datasetName.toStringz,cast(int)dims.length,dims.ptr,data.ptr)>=0, 143 new Exception("H5Lite.make!char error")); 144 } 145 146 void make(hid_t locID,string datasetName, hsize_t[] dims, hid_t typeID, in short[] data) 147 { 148 enforce(H5LTmake_dataset_short(locID,datasetName.toStringz,cast(int)dims.length,dims.ptr,data.ptr)>=0, 149 new Exception("H5Lite.make!short error")); 150 } 151 152 void make(hid_t locID,string datasetName, hsize_t[] dims, hid_t typeID, in int[] data) 153 { 154 enforce(H5LTmake_dataset_int(locID,datasetName.toStringz,cast(int)dims.length,dims.ptr,data.ptr)>=0, 155 new Exception("H5Lite.make!int error")); 156 } 157 void make(hid_t locID,string datasetName, hsize_t[] dims, hid_t typeID, in long[] data) 158 { 159 enforce(H5LTmake_dataset_long(locID,datasetName.toStringz,cast(int)dims.length,dims.ptr,data.ptr)>=0, 160 new Exception("H5Lite.make!long error")); 161 } 162 void make(hid_t locID,string datasetName, hsize_t[] dims, hid_t typeID, in float[] data) 163 { 164 enforce(H5LTmake_dataset_float(locID,datasetName.toStringz,cast(int)dims.length,dims.ptr,data.ptr)>=0, 165 new Exception("H5Lite.make!float error")); 166 } 167 void make(hid_t locID,string datasetName, hsize_t[] dims, hid_t typeID, in double[] data) 168 { 169 enforce(H5LTmake_dataset_double(locID,datasetName.toStringz,cast(int)dims.length,dims.ptr,data.ptr)>=0, 170 new Exception("H5Lite.make!double error")); 171 } 172 void make(hid_t locID,string datasetName, hsize_t[] dims, hid_t typeID, in string data) 173 { 174 enforce(H5LTmake_dataset_string(locID,datasetName.toStringz,data.ptr)>=0, 175 new Exception("H5Lite.make!string error")); 176 } 177 178 /** 179 180 Read dataset functions 181 182 */ 183 184 herr_t H5LTread_dataset( hid_t loc_id, const (char*) dset_name, hid_t type_id, void *buffer ); 185 186 void read(hid_t loc_id, string datasetName,char* buf) 187 { 188 enforce(H5LT_read_dataset_char(loc_id,datasetName.toStringz,buf)>=0,new Exception("H5Lite.read!char error")); 189 } 190 191 void read(hid_t loc_id, string datasetName, short* buf) 192 { 193 enforce(H5LT_read_dataset_short(loc_id,datasetName.toStringz,buf)>=0,new Exception("H5Lite.read!short error")); 194 } 195 196 void read(hid_t loc_id, string datasetName, int* buf) 197 { 198 enforce(H5LT_read_dataset_int(loc_id,datasetName.toStringz,buf)>=0,new Exception("H5Lite.read!int error")); 199 } 200 201 void read(hid_t loc_id, string datasetName, long* buf) 202 { 203 enforce(H5LT_read_dataset_long(loc_id,datasetName.toStringz,buf)>=0,new Exception("H5Lite.read!long error")); 204 } 205 206 void read(hid_t loc_id, string datasetName, long* buf) 207 { 208 enforce(H5LT_read_dataset_long(loc_id,datasetName.toStringz,buf)>=0,new Exception("H5Lite.read!long error")); 209 } 210 211 void read(hid_t loc_id, string datasetName, float* buf) 212 { 213 enforce(H5LT_read_dataset_float(loc_id,datasetName.toStringz,buf)>=0,new Exception("H5Lite.read!float error")); 214 } 215 216 void read(hid_t loc_id, string datasetName, double* buf) 217 { 218 enforce(H5LT_read_dataset_double(loc_id,datasetName.toStringz,buf)>=0,new Exception("H5Lite.read!double error")); 219 } 220 221 void read(hid_t loc_id, string datasetName, char* buf) 222 { 223 enforce(H5LT_read_dataset_string(loc_id,datasetName.toStringz,buf)>=0,new Exception("H5Lite.read!char error")); 224 } 225 226 /** 227 228 Query dataset functions 229 230 */ 231 232 int getDataSetNumDims(hid_t locID, string datasetName) 233 { 234 int ret; 235 enforce(H5LTget_dataset_ndims(locID,datasetName.toStringz,&ret)>=0,new ExceptioN("H5Lite.getDataSetNumDims error")); 236 return ret; 237 } 238 239 int getDataSetSize(hid_t locID, string datasetName) 240 { 241 hsize_t dims, 242 H5T_class_t typeClass; 243 size_t typeSize; 244 enforce(H5LTget_dataset_info(locID,datasetName.toStringz,&dims,&typeClass,&typeSize ); 245 return typeSize; 246 } 247 248 H5T_class_t getDataSetClass(hid_t loc_id, string datasetName) 249 { 250 hsize_t dims, 251 H5T_class_t typeClass; 252 size_t typeSize; 253 enforce(H5LTget_dataset_info(locID,datasetName.toStringz,&dims,&typeClass,&typeSize ); 254 return typeClass; 255 } 256 257 alias H5LiteInfo=Tuple!(dims,"dims",H5T_class_t,"typeClass",size_t,"typeSize"); 258 H5LiteInfo getDataSetInfo(hid_t loc_id, string datasetName) 259 { 260 hsize_t dims, 261 H5T_class_t typeClass; 262 size_t typeSize; 263 enforce(H5LTget_dataset_info(locID,datasetName.toStringz,&dims,&typeClass,&typeSize ); 264 return H5LiteInfo(dims,typeClass,typeSize); 265 } 266 267 bool canFindDataset(hid_t locID, string datasetName) 268 { 269 return (H5LTfind_dataset(locID, datasetName.toStringz)==1); 270 } 271 272 /** 273 274 Set attribute functions 275 276 */ 277 278 void setAttribute(hid_t locID, string objectName, string attributeName, in char* data) 279 { 280 enforce(H5LTset_attribute_string(locID,objectName.toStringz,attributeName.toStringz,data)>=0, 281 new Exception("H5Lite.setAttribute!char error")); 282 } 283 void setAttribute(hid_t locID, string objectName, string attributeName, in uchar* data) 284 { 285 enforce(H5LTset_attribute_uchar(locID,objectName.toStringz,attributeName.toStringz,data)>=0, 286 new Exception("H5Lite.setAttribute!uchar error")); 287 } 288 void setAttribute(hid_t locID, string objectName, string attributeName, in short[] data) 289 { 290 enforce(H5LTset_attribute_short(locID,objectName.toStringz,attributeName.toStringz,data.ptr,data.length)>=0, 291 new Exception("H5Lite.setAttribute!short[] error")); 292 } 293 void setAttribute(hid_t locID, string objectName, string attributeName, in ushort[] data) 294 { 295 enforce(H5LTset_attribute_ushort(locID,objectName.toStringz,attributeName.toStringz,data.ptr,data.length)>=0, 296 new Exception("H5Lite.setAttribute!ushort[] error")); 297 } 298 void setAttribute(hid_t locID, string objectName, string attributeName, in int[] data) 299 { 300 enforce(H5LTset_attribute_int(locID,objectName.toStringz,attributeName.toStringz,data.ptr,data.length)>=0, 301 new Exception("H5Lite.setAttribute!int[] error")); 302 } 303 void setAttribute(hid_t locID, string objectName, string attributeName, in uint[] data) 304 { 305 enforce(H5LTset_attribute_uint(locID,objectName.toStringz,attributeName.toStringz,data.ptr,data.length)>=0, 306 new Exception("H5Lite.setAttribute!uint[] error")); 307 } 308 void setAttribute(hid_t locID, string objectName, string attributeName, in long[] data) 309 { 310 enforce(H5LTset_attribute_long(locID,objectName.toStringz,attributeName.toStringz,data.ptr,data.length)>=0, 311 new Exception("H5Lite.setAttribute!long[] error")); 312 } 313 void setAttribute(hid_t locID, string objectName, string attributeName, in ulong[] data) 314 { 315 enforce(H5LTset_attribute_ulong(locID,objectName.toStringz,attributeName.toStringz,data.ptr,data.length)>=0, 316 new Exception("H5Lite.setAttribute!uint[] error")); 317 } 318 void setAttribute(hid_t locID, string objectName, string attributeName, in float[] data) 319 { 320 enforce(H5LTset_attribute_float(locID,objectName.toStringz,attributeName.toStringz,data.ptr,data.length)>=0, 321 new Exception("H5Lite.setAttribute!float[] error")); 322 } 323 void setAttribute(hid_t locID, string objectName, string attributeName, in double[] data) 324 { 325 enforce(H5LTset_attribute_double(locID,objectName.toStringz,attributeName.toStringz,data.ptr,data.length)>=0, 326 new Exception("H5Lite.setAttribute!double[] error")); 327 } 328 329 /** 330 331 Get attribute functions 332 333 */ 334 335 herr_t H5LTget_attribute( hid_t loc_id, const (char*) obj_name, const (char*) attr_name, hid_t mem_type_id, void *data ); 336 herr_t H5LTget_attribute_string( hid_t loc_id, const (char*) obj_name, const (char*) attr_name, char *data ); 337 338 void getAttribute(hid_t locID, string objectName, string attributeName, char* data) 339 { 340 enforce(H5LTget_attribute_char(locID,objectName.toStringz,attributeName.toStringz,data)>=0, 341 new Exception("H5Lite.getAttribute!char")); 342 } 343 344 void getAttribute(hid_t locID, string objectName, string attributeName, uchar* data) 345 { 346 enforce(H5LTget_attribute_uchar(locID,objectName.toStringz,attributeName.toStringz,data)>=0, 347 new Exception("H5Lite.getAttribute!uchar")); 348 } 349 void getAttribute(hid_t locID, string objectName, string attributeName, short* data) 350 { 351 enforce(H5LTget_attribute_short(locID,objectName.toStringz,attributeName.toStringz,data)>=0, 352 new Exception("H5Lite.getAttribute!short")); 353 } 354 void getAttribute(hid_t locID, string objectName, string attributeName, ushort* data) 355 { 356 enforce(H5LTget_attribute_ushort(locID,objectName.toStringz,attributeName.toStringz,data)>=0, 357 new Exception("H5Lite.getAttribute!ushort")); 358 } 359 void getAttribute(hid_t locID, string objectName, string attributeName, int* data) 360 { 361 enforce(H5LTget_attribute_int(locID,objectName.toStringz,attributeName.toStringz,data)>=0, 362 new Exception("H5Lite.getAttribute!int")); 363 } 364 void getAttribute(hid_t locID, string objectName, string attributeName, uint* data) 365 { 366 enforce(H5LTget_attribute_uint(locID,objectName.toStringz,attributeName.toStringz,data)>=0, 367 new Exception("H5Lite.getAttribute!uint")); 368 } 369 void getAttribute(hid_t locID, string objectName, string attributeName, long* data) 370 { 371 enforce(H5LTget_attribute_long(locID,objectName.toStringz,attributeName.toStringz,data)>=0, 372 new Exception("H5Lite.getAttribute!long")); 373 } 374 void getAttribute(hid_t locID, string objectName, string attributeName, ulong* data) 375 { 376 enforce(H5LTget_attribute_ulong(locID,objectName.toStringz,attributeName.toStringz,data)>=0, 377 new Exception("H5Lite.getAttribute!ulong")); 378 } 379 void getAttribute(hid_t locID, string objectName, string attributeName, float* data) 380 { 381 enforce(H5LTget_attribute_float(locID,objectName.toStringz,attributeName.toStringz,data)>=0, 382 new Exception("H5Lite.getAttribute!float")); 383 } 384 void getAttribute(hid_t locID, string objectName, string attributeName, double* data) 385 { 386 enforce(H5LTget_attribute_double(locID,objectName.toStringz,attributeName.toStringz,data)>=0, 387 new Exception("H5Lite.getAttribute!double")); 388 } 389 390 391 /** 392 393 Query attribute functions 394 395 */ 396 397 int getAttributeNumDims(hid_t locID, string objectName, string attributeName) 398 { 399 int numDims; 400 enforce(H5LT_get_attribute_ndims(locID,objectName.toStringz, attributeName.toStringz,&numDims)>=0, 401 new Exception("H5Lite.getAttributeNumDims error")); 402 return numDims; 403 } 404 405 H5T_class_t getAttributeClassType(hid_t locID, string objectName, string attributeName) 406 { 407 int numDims; 408 H5T_class_t classType; 409 size_t typeSize; 410 enforce(H5LT_get_attribute_info(locID,objectName.toStringz, attributeName.toStringz,&numDims,&classType,&typeSize)>=0, 411 new Exception("H5Lite.getAttributeNumDims error")); 412 return classType; 413 } 414 415 H5T_class_t getAttributeTypeSize(hid_t locID, string objectName, string attributeName) 416 { 417 int numDims; 418 H5T_class_t classType; 419 size_t typeSize; 420 enforce(H5LT_get_attribute_info(locID,objectName.toStringz, attributeName.toStringz,&numDims,&classType,&typeSize)>=0, 421 new Exception("H5Lite.getAttributeNumDims error")); 422 return typeSize; 423 } 424 425 H5LiteInfo getAttributeInfo(hid_t locID, string objectName, string attributeName) 426 { 427 int numDims; 428 H5T_class_t classType; 429 size_t typeSize; 430 enforce(H5LT_get_attribute_info(locID,objectName.toStringz, attributeName.toStringz,&numDims,&classType,&typeSize)>=0, 431 new Exception("H5Lite.getAttributeNumDims error")); 432 return H5LiteInfo(numDims,classType,typeSize); 433 } 434 435 436 /** 437 438 General functions 439 440 */ 441 442 hid_t H5LTtext_to_dtype(const (char*) text, H5LT_lang_t lang_type); 443 herr_t H5LTdtype_to_text(hid_t dtype, char *str, H5LT_lang_t lang_type, size_t *len); 444 445 /** 446 447 Utility functions 448 449 */ 450 451 bool canFindAttribute(hid_t locID,string name) 452 { 453 return (H5LTfind_attribute(locID,name.toStringz)==1); 454 } 455 456 bool isPathValid(hid_t locID, string path, bool checkObjectValid) 457 { 458 auto ret=H5LTpath_valid(locID,path.toStringz,checkObjectValid?1:0); 459 enforce(ret>=0, new Exception("H5Lite.isPathValid error"); 460 return (ret!=0); 461 } 462 463 /** 464 465 File image operations functions 466 467 */ 468 469 hid_t openFileImage(ubyte[] buf,bool readOnly,bool dontCopy) 470 { 471 auto ret=H5LTopen_file_image(buf.ptr,buf.length, (!readOnly?H5LT_FILE_IMAGE_OPEN_RW:0) | 472 (!dontCopy?H5LT_FILE_IMAGE_DONT_COPY:0) | 473 H5LT_FILE_IMAGE_DONT_RELEASE ); 474 enforce(ret>=0, new Exception("H5Lite.openFileImage error"); 475 return ret; 476 } 477 478 /** 479 H5PTpublic 480 */ 481 482 /** 483 484 Create/Open/Close functions 485 486 */ 487 488 hid_t H5PTcreate_fl ( hid_t loc_id, const (char*) dset_name, hid_t dtype_id, hsize_t chunk_size, int compression ); 489 static if (VLPT_REMOVED) 490 hid_t H5PTcreate_vl ( hid_t loc_id, const (char*) dset_name, hsize_t chunk_size ); 491 492 hid_t H5PTopen( hid_t loc_id, const (char*) dset_name ); 493 herr_t H5PTclose( hid_t table_id ); 494 495 /** 496 497 Write functions 498 499 */ 500 501 herr_t H5PTappend( hid_t table_id, size_t nrecords, const (void*) data ); 502 503 /** 504 505 Read functions 506 507 */ 508 509 herr_t H5PTget_next( hid_t table_id, size_t nrecords, void * data ); 510 herr_t H5PTread_packets( hid_t table_id, hsize_t start, size_t nrecords, void *data ); 511 512 /** 513 514 Inquiry functions 515 516 */ 517 518 519 herr_t H5PTget_num_packets( hid_t table_id, hsize_t *nrecords ); 520 herr_t H5PTis_valid( hid_t table_id ); 521 static if (VLPT_REMOVED) 522 herr_t H5PTis_varlen( hid_t table_id ); 523 524 /** 525 526 Packet Table "current index" functions 527 528 */ 529 530 herr_t H5PTcreate_index( hid_t table_id ); 531 herr_t H5PTset_index( hid_t table_id, hsize_t pt_index ); 532 herr_t H5PTget_index( hid_t table_id, hsize_t *pt_index ); 533 534 /** 535 536 Memory Management functions 537 538 */ 539 540 static if (VLPT_REMOVED) 541 herr_t H5PTfree_vlen_readbuff( hid_t table_id, size_t bufflen, void * buff ); 542 543 /** 544 H5TBpublic 545 */ 546 547 struct H5Table 548 { 549 550 string tableTitle; 551 string datasetName; 552 hid_t locID; 553 string[] fieldNames; 554 size_t[] fieldOffsets; 555 hid_t[] fieldTypes; 556 size_t[] fieldSizes; 557 size_t typeSize; 558 bool compress=false; 559 /** 560 561 Create functions 562 563 */ 564 this(string tableTitle,string datasetName,hid_t locID, string[] fieldNames, size_t[] fieldOffsets, hid_t[] fieldTypes, size_t typeSize, 565 size_t[] fieldSizes,bool compress=false) 566 { 567 this.tableTitle=tableTitle; 568 this.datasetName=datasetName; 569 this.locID=locID; 570 this.fieldNames=fieldNames; 571 this.fieldOffsets=fieldOffsets; 572 this.fieldTypes=fieldTypes; 573 this.typeSize=typeSize; 574 this.fieldSizes=fieldSizes 575 this.compress=compress; 576 } 577 578 void makeTable(T)(hsize_t chunkSize, bool compress=false, T data) 579 { 580 ubyte[] fillData; 581 fillData.length=this.typeSize; 582 makeTable!T(chunkSize,fillData,compress,data); 583 } 584 585 void makeTable(T)(hsize_t chunkSize, ubyte[] fillData, bool compress=false, T data) 586 { 587 auto numFields=fieldNames.length; 588 auto numRecords=data.length; 589 enforce(numFields==fieldOffsets.length,new Exception("H5Table.makeTable: fieldNames must have same length as fieldOffsets"); 590 enforce(numFields==fieldTypes.length,new Exception("H5Table.makeTable: fieldNames must have same length as fieldTypes"); 591 592 enforce(H5TBmake_table(toStringz(tableTitle),locID,toStringz(datasetName),numFields,numRecords,typeSize,names.toCPointerArray, 593 fieldOffsets.ptr,fieldTypes.ptr,chunkSize,fillData.ptr,compress?-1:0, buf.ptr)>=0,new Exception("H5Table.makeTable error")); 594 } 595 596 597 /** 598 599 Write functions 600 601 */ 602 603 void appendRecords(T)(in T[] data) 604 { 605 auto numRecords=data.length; 606 enforce(H5TBappend_records(locID,datasetName.toStringz, numRecords, typeSize, fieldOffsets.ptr,fieldSizes.ptr,data.ptr)>=0, 607 new Exception("H5Table.appendRecords error")); 608 } 609 610 void writeRecords(T)(hsize_t start, in T[] data) 611 { 612 auto numRecords=data.length; 613 enforce(H5TB_write_records(locID,datasetName.toStringz, start, numRecords,typeSize,fieldOffsets.ptr,fieldSizes.ptr,data.ptr)>=0, 614 new Exception("H5Table.writeRecords error")); 615 } 616 617 618 void writeFieldsName(T)(hsize_t start, in T[] data) 619 { 620 auto numRecords=data.length 621 enforce(H5TB_write_fields_name(locID,datasetName.ptr,fieldNames.toCPointerArray,start,numRecords,typeSize,fieldOffsets.ptr, 622 fieldSizes.ptr,data.ptr)>=0, new Exception("H5Table.writeFieldsName error")); 623 } 624 625 void writeFieldsIndex(T)(in int[] fieldIndex, hsize_t start, in T[] data) 626 { 627 auto numRecords=data.length; 628 enforce(H5TBwrite_fields_index(locID,datasetName.toStringz,numFields,fieldIndex.ptr,start,numRecords,typeSize,fieldOffsets.ptr, 629 destSizes.ptr,data.ptr)>=0,new Exception("H5Table.writeFieldsIndex error")); 630 } 631 632 /** 633 634 Read functions 635 636 */ 637 638 void readTable(T)(size_t destSize, in size_t[] destOffset, in size_t[] destSizes, ubyte[] buf) 639 { 640 enforce(H5TBread_table(locID,datasetName.toStringz,fieldSizes,fieldOffsets.ptr,fieldSizes.ptr,data.ptr)>=0, 641 new Exception("H5Table.readTable error")); 642 } 643 644 void readFieldsName(T)(string[] fieldNames, hsize_t start, hsize_t numRecords,in T[] data) 645 { 646 auto numRecords=data.length; 647 enforce(H5TBread_fields_name(locID,datasetName.toStringz,fieldNames.toCPointerArray,start,numRecords,typeSize,fieldOffsets.ptr, 648 destSizes.ptr,buf.ptr)>=0,new Exception("H5Table.readFieldsName error")); 649 } 650 651 void readFieldsIndex(hid_t locID, string datasetName, hsize_t numFields) 652 653 654 655 656 657 658 659 herr_t H5TBread_fields_index( hid_t loc_id, const (char*) dset_name, hsize_t nfields, const int *field_index, hsize_t start, 660 hsize_t nrecords, size_t type_size, const size_t *field_offset, const size_t *dst_sizes, void *buf ); 661 662 663 herr_t H5TBread_records( hid_t loc_id, const (char*) dset_name, hsize_t start, hsize_t nrecords, size_t type_size, 664 const size_t *dst_offset, const size_t *dst_sizes, void *buf ); 665 666 667 /** 668 669 Inquiry functions 670 671 */ 672 673 herr_t H5TBget_table_info ( hid_t loc_id, const (char*) dset_name, hsize_t *nfields, hsize_t *nrecords ); 674 herr_t H5TBget_field_info( hid_t loc_id, const (char*) dset_name, char *field_names[], size_t *field_sizes, size_t *field_offsets, 675 size_t *type_size ); 676 677 678 /** 679 680 Manipulation functions 681 682 */ 683 684 void deleteRecord(hsize_t start, hsize_t numRecords) 685 { 686 enforce(H5TB_delete_record(locID,datasetName.toStringz,start,numRecords)>=0,new Exception("H5Table.deleteRecord error")); 687 } 688 689 void insertRecord(T)(hsize_t start, T data) 690 { 691 enforce(H5TBinsert_record(locID,datasetName.toStringz, start,data.length, fieldSizes.ptr, fieldOffsets.ptr,fieldSizes.ptr,data.ptr) 692 >=0, new Exception("H5Table.insertRecord error")); 693 } 694 695 void addRecordsFrom(hsize_t start1, hsize_t numRecords, hsize_t start2, H5Table dataset2) 696 { 697 enforce H5TB_add_records_from(locID,datasetName.toStringz,start1,numRecords,dataset2.datasetName,start2)>=0, 698 new Exception("H5Table.addRecordsFrom error"); 699 } 700 701 void combineTables(H5Table dataset2 702 herr_t H5TBcombine_tables( hid_t loc_id1, const (char*) dset_name1, hid_t loc_id2, const (char*) dset_name2, const (char*) dset_name3 ); 703 herr_t H5TBinsert_field( hid_t loc_id, const (char*) dset_name, const (char*) field_name, hid_t field_type, hsize_t position, 704 const (void*) fill_data, const (void*) buf ); 705 herr_t H5TBdelete_field( hid_t loc_id, const (char*) dset_name, const (char*) field_name ); 706 707 708 /** 709 710 Table attribute functions 711 712 */ 713 714 string getTableTitle(hid_t locID) 715 { 716 string 717 } 718 herr_t H5TBAget_title( hid_t loc_id, char *table_title ); 719 htri_t H5TBAget_fill(hid_t loc_id, const (char*) dset_name, hid_t dset_id, ubyte *dst_buf); 720 721 +/